package com.yanqu.road.logic.helper;

public class PowerHelper {
    /**
     * 计算体力恢复
     *
     * @param lastRestoreTime      最后一次恢复体力时间 秒
     * @param recoverDuration      恢复体力间隔 秒
     * @param recoverValuePerTimes 每次间隔恢复几点体力
     * @param maxPower             最大体力
     * @param curPower             当前体力
     * @return
     */
    public static CalcPowerResult calcPower(long lastRestoreTime, long recoverDuration, int recoverValuePerTimes, int maxPower, int curPower) {
        long now = System.currentTimeMillis() / 1000;
        if (curPower >= maxPower) {
            //当前值已经超过最大值 则为当前值
            return new CalcPowerResult(curPower, now);
        }
        if (lastRestoreTime >= now) {
            //最后一次恢复时间大于当前时间 则为当前值
            return new CalcPowerResult(curPower, lastRestoreTime);
        }
        int addTimes = (int) ((now - lastRestoreTime) / recoverDuration);
        int addPower = addTimes * recoverValuePerTimes;
        curPower = Math.min(curPower + addPower, maxPower);
        if (curPower >= maxPower) {
            return new CalcPowerResult(maxPower, now);
        }
        return new CalcPowerResult(curPower, lastRestoreTime + addTimes * recoverDuration);
    }
}
